<!doctype html>
<html>
<style>
	.my_yaoq{
		color: #42A5F7;
	    height: 2.5rem;
	    line-height: 2.5rem;
	    background: white;
	    text-align: center;
	    font-size: 1rem;
	    width: 60%;
	    margin: 1.2rem 0 0 20%;
	    border: 1px solid #42A5F7;
	}
</style>
	<head>
		<meta charset="UTF-8">
		<title>云商圈</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="__INDEX__/css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="__INDEX__/css/style.css" />
		<link rel="stylesheet" href="__INDEX__/css/iconfont.css" />
		<link rel="stylesheet" href="__INDEX__/css/mall.css" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-icon mui-icon-left-nav mui-pull-left" id="return"></a>
			<h1 class="mui-title">云商圈</h1>

		</header>
		<div class="mui-content" style="height: 100%;">
			<form id='my_form' class="mui-input-group gerenzl_group layui-form update_form" style="height: 100%;">
				<ul class="fjysq_slis">
					<li class="clearfix">
						<div class="left">联盟头像</div>
						<div class="right toux">
							<div class="layui-upload-list" style="margin: unset;">
								<button id="test1" type="button" class="file-btn" style="border: 0px;">
						    <img class="layui-upload-img" id="logo" src = "{if isset($data) }{$data.thumb}{/if}" style="border: 0px;">
						    <input type="hidden" name='thumb' value="{if isset($data) }{$data.thumb}{/if}" id='thumb' />
						</button>
								<p id="demoText"></p>
							</div>
						</div>
					</li>
					<li class="clearfix">
						<div class="left">联盟名称</div>
						<div class="right clearfix"><input type="text" id="name" value="{if isset($data) }{$data.name}{/if}" name="name" placeholder="请填写联盟名称"></div>
					</li>
					<li class="clearfix">
						<div class="left">商圈名</div>
						<div class="right clearfix"><input type="text" id="sq_name" value="{if isset($data) }{$data.sq_name}{/if}" name="sq_name" placeholder="如：北湖商圈"></div>
					</li>
					<li class="clearfix">
						<div class="left">单客次广告费</div>
						<div class="right clearfix">
							<lable disabled="true" type="text" value="0.1" style="width: 80%;margin-right: 5%;">0.2
								<lable>元</lable>
						</div>
					</li>
					<li class="clearfix">
						<div class="left">联系电话</div>
						<div class="right clearfix"><input type="text" value="{if isset($data) }{$data.tel}{/if}" name="tel" id='tel' placeholder="请填写联系电话"></div>
					</li>
					<li class="clearfix">
						<div class="left">描述</div>
						<div class="right clearfix"><input type="text" value="{if isset($data) }{$data.content}{/if}" name="content" id='content' placeholder="请添加描述"></div>
					</li>
				</ul>
				{if isset($data) && $data['is_create'] == 1} 
					{if $data['state'] == 2}
						<button type="button" id="item_list" style="display: block;">成员列表</button> 
						<button type="button" id="invite_agent" class="my_yaoq" style="display: block;">邀请商家入驻</button> 
					{else}
						<button type="button" class="fjysq_sbtn" style="display: block;">已提交，等审核</button> 
					{/if} 
				{else}
					<button type="button" onclick="set_content()" class="fjysq_sbtn" style="display: block;">提交申请</button> 
				{/if}
		</div>
		</form>
		{include file="public/footer" /}
	</body>

</html>

<script>
	//成员列表
	$("#item_list").click(function() {
		parent.location.href = "{:url('member/union_memberlist')}"
	});
	//成员列表
	$("#invite_agent").click(function() {
		parent.location.href = "{:url('member/yaoqsjrz')}"
	});
</script>
<script>
	$('#return').click(function() {
		window.location.href = "{:url('member/index')}";
	});
	//提交表单
	function set_content() {
		if($("#thumb").val() == "" || $("#thumb").val() == null) {
			layer.msg("联盟logo不能为空");
			$("#logo").focus();
			return false
		}
		if($("#name").val() == "" || $("#name").val() == null) {
			layer.msg("请输入联盟名称");
			$("#name").focus();
			return false
		}
		if($("#sq_name").val() == "" || $("#sq_name").val() == null) {
			layer.msg("请输入商圈名");
			$("#sq_name").focus();
			return false
		}
		if($("#tel").val() == "" || $("#tel").val() == null) {
			layer.msg("请输入联系电话");
			$("#tel").focus();
			return false
		}
		$.ajax({
			type: "post",
			url: "{:url('index/member/union')}",
			data: $('#my_form').serialize(), //表单数据
			success: function(data) {
				layer.msg(data.msg, {
					icon: 1,
					time: 1500 //2秒关闭（如果不配置，默认是3秒）
				}, function() {
					location.reload();
				});
			}
		});

	}
</script>
<script>
	//图片上传
	layui.use(['form', 'upload'], function() {
		var $ = layui.jquery,
			upload = layui.upload,
			form = layui.form;

		//普通图片上传
		var uploadInst = upload.render({
			elem: '#test1',
			auto: false //选择文件后不自动上传
				,
			choose: function(obj) {
				//将每次选择的文件追加到文件队列
				var files = obj.pushFile();

				//预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
				obj.preview(function(index, file, result) {
					$('#logo').attr('src', result); //图片链接（base64）
					var sendData = result.substring(result.indexOf(";base64,") + 8);
					$.post("{:url('index/member/upload')}", {
						value: sendData
					}, function(data) {
						if(data.code == '200') {
							$('#thumb').val(data.url);
						} else {
							layer.msg(data.msg);
						}
					});
				});
			},
			url: "{:url('index/member/upload')}",
			accept: 'images'
		});
	})
</script>